package main

import "fmt"

/**
	接口中所有方法被一个对象实现，则可以把对象信息赋值给接口变量，通过接口调用方法
 */
func main() {
	stu := student{
		name: "张三",
		age: 18,
		score: 80,
	}
	teacher := teacher{
		name:    "老师",
		age:     28,
		subject: "数学",
	}
	//stu.sayHi()
	//teacher.sayHi()

	var human Humaner
	//将对象信息赋值给接口变量
	human = &stu
	human.sayHi()

	human = &teacher
	human.sayHi()

}

type student struct {
	name	string
	age		int
	score	int
}

type teacher struct {
	name	string
	age		int
	subject	string
}
type Humaner interface {
	sayHi()
}

func (stu *student) sayHi() {
	fmt.Printf("大家好，我是%s，今年%d 岁，我的分数是 %d\n",stu.name,stu.age,stu.score)
}

func (teacher *teacher) sayHi() {
	fmt.Printf("大家好，我是%s，今年%d 岁，我的学科是 %s",teacher.name,teacher.age,teacher.subject)
}